{extends file="./main.tpl"}
{block name=head}
<link href="./css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<link href="./css/loan.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/jquery.autocomplete.pack.js"></script>
<script type="text/javascript" src="./js/loan.js"></script>
<script type="text/javascript" src="./js/script.js"></script>	
<script type="text/javascript">
  function valueTotal()
  {
    var goldValue = document.getElementById('goldValue').value;
    var propartyValue = document.getElementById('propartyValue').value;
    var total = Number(goldValue) + Number(propartyValue);
    $('#loanAmount').val(total);
    $('#value1').val(total);
  }
  function calculatFine()
  {
    var grossWeight = $('#grossWeight').val();
    var less = $('#less').val();
    var purity = $('#purity').val();
    var fine1 = ((Number(grossWeight) - Number(less)) * Number(purity))/100 ;
    $('#fine').val(fine1);
  }
  function calculatValue()
  {
  	var grossWeight = $('#grossWeight').val();
    var less = $('#less').val();
    var purity = $('#purity').val();
    var fine1 = ((Number(grossWeight) - Number(less)) * Number(purity))/100 ;
    $('#fine').val(fine1);
    var Rate = $('#Rate').val();
    var fine = $('#fine').val();
    var ValueVar = fine * Rate / 10 ; 
    $('#goldValue').val(ValueVar);
  }
  

//  function addNewRow()
//  {
//    $('#loanTable tr:last').after('<tr class="transactionInRow"><td colspan="2" align="center"><input type="text" name=transactionIn[]" id="transactionIn" class="transactionInClass" autocomplete="off" size="24" /></td><td><textarea name="amountNarration[]"></textarea></td><td align="center"><input type="text" name="amount1[]" id="amount1" size="24" onkeyup="amount();" /></td><td align="center"><input type="text" name="amount2[]" id="amount2" size="24" /></td><td align="center"><a href="javascript:addNewRow();"> Add</a></td></tr>');
//  }
  function landConstructionTotal()
  {
    var landValue = document.getElementById('landValue').value;
    var constructionValue = document.getElementById('constructionValue').value;
    var total = Number(landValue) + Number(constructionValue);
    $('#propartyValue').val(total);
  }
//  $(document).ready(function(){
//    $(".amount1Class").blur(function()
//	  {
//	  	alert("ok");
//	   if($(".amount1Class:last").val() != '' && $(".amount1Class:last").val() > 0)
//	   {
//      $("#one").clone(true).appendTo("#mainDiv")
//      .find('input[type="text"]').val('').end()
//      .find('taxtarea').val('');
//    }
//    });
//  });
  var totalAmount1 = 0;
  var totalAmount2 = 0;
  function amountClass(amtObj)
  {
  	var row = $(amtObj).parents('.amtRow');
  	if($(".amount1Class:last").val() != '' && $(".amount1Class:last").val() > 0)
	  {
      $("#one").clone(true).appendTo('#mainDiv')
      .find('input[type="text"]').val('').end()
      .find('taxtarea').val('');
    }
    var amount = amtObj.value;
    row.find('.amount2Class').val(amount);
    
    //logic for total of amount2 onkeypress in amount1
    var totleAmount2 = 0;
    $('.amount2Class').each(function(i)
    {
      amount2Class = $(this).val().replace("$","");
      if(!isNaN(amount2Class))
      {
        totleAmount2 += Number(amount2Class);
      }
    });
    $('#totleAmount2').val(totleAmount2.toFixed(2));
    
    //logic for total of amount1 onkeypress in amount
    var totleAmount1 = 0;
    $('.amount1Class').each(function(i)
    {
      amount1Class = $(this).val().replace("$","");
      if(!isNaN(amount1Class))
      {
        totleAmount1 += Number(amount1Class);
      }
    });
    $('#totleAmount1').val(totleAmount1.toFixed(2));
  }
  
  function addInAmount2()
  {
  	//logic for total of amount2 onkeypress in amount2
  	var totleAmount2 = 0;
    $('.amount2Class').each(function(i)
    {
      amount2Class = $(this).val().replace("$","");
      if(!isNaN(amount2Class))
      {
        totleAmount2 += Number(amount2Class);
      }
    });
    $('#totleAmount2').val(totleAmount2.toFixed(2));
  }
  
  // check the total amount one is same as loan amount or not
//  function compairLoanAmount()
//  {
//    var totleAmount1 = $('#totleAmount1').val();
//    var loanAmount = $('#loanAmount').val();
//    var comparision = parseInt(totleAmount1) -  parseInt(loanAmount);
//    alert(comparision);
//    if(comparision != 0)
//    {
//      alert("total amount is not equal to loan amount");
//      return false();
//    }
//    else
//    {
//      retur true();
//    }
//  }

function savePrint()
{      
  var c = document.getElementById('hiddenId').value = "1";
}
</script>
{/block}
{block name=body}
<h1>Last Loan No. {$lastId}</h1>
<form name="loanForm" id="loanForm" action="{$smarty.server.PHP_SELF}" method="post" enctype="multipart/form-data" onsubmit="return confirm('DO You Want To Submit !!!!!')";>
  <table cellpadding="2" cellspacing="0" border="0" align="center">
    <tr>
      <td align="right" valign="top" >
  	    <table cellpadding="2" cellspacing="0" border="1" id="loanTable" >
  	      <tr>
  	        <td colspan="6" align="center" style="background:#EBF5FF;">
  	        	<h1><font size="5px">Loan Entry</font></h1>
  	        	<span style="color:red">{$msg}</span>
  	        </td>
  	      </tr>
  	      <!---<tr>
            <th align="right" colspan="3"> Take Image : &nbsp</th>
            <td colspan="3">&nbsp<a href="webcam/web.html"> <font size="2px">Take Image</font></a></td>
          </tr>-->
  	      <tr>
            <th align="right" colspan="3">Loan G/T : &nbsp</th>
            <td colspan="3">
              &nbsp<select name="">
                <option value="Give">Give</option>
                <option value="Take">Take</option>
              </select>
            </td>
          </tr>
  	      <tr>
            <th align="right" colspan="3">Party : &nbsp</th>
            <td colspan="3">
              &nbsp<select name="accountIdOld" id="accountIdOld" autofocus="autofocus" onchange="findGuaranterId(this);">
                <option value="0">&nbsp&nbsp&nbsp --- New Party --- &nbsp&nbsp&nbsp  </option>
                {html_options values=$arrParty.accountId  output=$arrParty.accountName}
              </select>
            </td>
          </tr>
          <tr>
            <th align="right" colspan="3">Loan Type : &nbsp</th>
            <td colspan="3">
              &nbsp<select name="loanType" >
                {html_options values=$loanTypeArr output=$loanTypeArr}
              </select>
            </td>
          </tr>
          <tr>
            <th colspan="6" rowspan="1" style="background:#EBF5FF;"><font color="green" size="4px">Loan On Gold</font></th>
          </tr>
          <tr>
            <th>Gross Weight</th>
            <th>Less</th>
            <th>Purity</th>
            <th>Fine</th>
            <th>Rate</th>
            <th>Value</th>
          </tr>
          <tr>
            <td><input type="text" size="5%" name="grossWeight" id="grossWeight" onkeyup="calculatValue();" value="{if $editLoanRow != null } {$editLoanRow['grossWeight']} {/if}"></td>
            <td><input type="text" size="5%" name="less" id="less" onkeyup="calculatValue();"></td>
            <td><input type="text" size="5%" name="purity" id="purity" onkeyup="calculatValue();"></td>
            <td><input type="text" size="5%" name="fine" id="fine" onkeyup="calculatValue();" readonly ></td>
            <td><input type="text" size="5%" name="Rate" id="Rate" onkeyup="calculatValue();"></td>
            <td><input type="text" size="5%" name="goldValue" id="goldValue" onkeyup="valueTotal();" readonly></td>
          </tr>
          <tr>
            <th colspan="6" style="background:#EBF5FF;"><font color="green" size="4px">Loan On Proparty</font></th>
          </tr>
          <tr>
            <th colspan="2">Land Value</th>
            <th colspan="2">Construction Value</th>
            <th colspan="2">Total</th>
          </tr>
          <tr>
            <td colspan="2" align="center"><input size="5%" type="text" name="landValue" id="landValue" onkeyup="landConstructionTotal();"></td>
            <td colspan="2" align="center"><input size="5%" type="text" name="constructionValue" id="constructionValue" onkeyup="landConstructionTotal();"></td>
            <td colspan="2" align="center"><input size="5%" type="text" name="propartyValue" id="propartyValue" onblur="valueTotal();" /></td>
          </tr>
          <tr>
            <th align="right" colspan="3">Value : &nbsp</th>
            <td colspan="3">&nbsp<input type="text" name="value" id="value1" size="24" placeholder="Value" /></td>
          </tr>
          <tr>
            <th align="right" colspan="3">Loan Amount : &nbsp</th>
            <td colspan="3">&nbsp<input type="text" required=required size="24" name="loadAmount" id="loanAmount" onblur="countDays();" placeholder="Enter Loan Amount"></td>
          </tr>
          <tr>
            <th align="right" colspan="3">Item Image : &nbsp</th>
            <td colspan="3">&nbsp<input type="file" name="file" id="file" ></td>
          </tr>
          <tr>
            <th align="right" colspan="3">Item Location : &nbsp</th>
            <td colspan="3">&nbsp<input type="text" required=required size="24" name="itemLocation" class="capital" id="itemLocation" ></td>
          </tr>
          <tr>
            <th align="right" colspan="3">Date : &nbsp</th>
            <td colspan="3">&nbsp{html_select_date prefix='curDate' field_order="DmY" month_format="%m" start_year='-5' end_year='+5' time=$today|date_format:"%d-%m-%Y" day_value_format="%02d"}</td>
          </tr>
          <tr>
            <th NOWRAP align="right" colspan="3">Last Insterest Received : &nbsp</th>
            <td  colspan="3">&nbsp{html_select_date prefix='lastInstRec' field_order="DmY" month_format="%m" start_year='-5' end_year='+5' time=$today|date_format:"%d-%m-%Y" day_value_format="%02d"}</td>
          </tr>
          <tr>
            <th NOWRAP align="right"  colspan="3">Loan End Date : &nbsp</th>
            <td  colspan="3">&nbsp{html_select_date prefix='endDate' field_order="DmY" month_format="%m" start_year='-5' end_year='+5' time=$today|date_format:"%d-%m-%Y" day_value_format="%02d"}</td>
          </tr>
          <tr>
            <th NOWRAP  align="right" colspan="3">Monthly Interest % : &nbsp</th>
            <td colspan="3">&nbsp<input type="text" name="monthlyInterest" size="24" required=required id="monthlyInterest" onblur="interest();"></td>
          </tr>
          <tr>
            <th NOWRAP align="right"  colspan="3">Monthly Interest Rs : &nbsp</th>
            <td colspan="3">&nbsp<input type="text" name="monthlyInterestRs" required=required size="24" id="monthlyInterestRs""></td>
            <input type="hidden" name="loanVar" id="loanVar"">
          </tr>
          <tr>
            <th colspan="6" rowspan="1" style="background:#EBF5FF;"><font color="green" size="4px">Account</font></th>
          </tr>
          <tr>
            <th colspan="2">Account</th>
            <th colspan="2">Narration</th>
            <th colspan="2">Amount</th>
          </tr>
          <tbody id="mainDiv"> 
          <tr  id="one" class="amtRow">
            <td colspan="2" align="center">
              <select name="accountId[]" >
              	<option value="0">-- Select Account --</option>
              	{html_options values=$selAccountArray.accountId  output=$selAccountArray.accountName}
              </select>
            </td>
            <td colspan="2"><textarea  size="5%" name="amountNarration[]"></textarea></td>
            <td align="center">
              <input type="text" size="5%" name="amount1[]" class="amount1Class" size="24" onkeyup="amountClass(this);" />
            </td>
            <td align="center" colspan="2"> 
              <input type="text" size="5%" name="amount2[]" class="amount2Class" size="24" onkeyup="addInAmount2();" />
            </td>
          </tr>
        </tbody>
        <tr>
        	<td colspan="2"></td>
          <th colspan="2">Total</th>
          <td><input type="text" name="totleAmount1"  size="5%" size="24" id="totleAmount1"></td>
          <td><input type="text" name="totleAmount2"  size="5%" size="24" id="totleAmount2"></td>
        </tr>
        </table> 
      </td>
      <td align="left" valign="top" class="partyData">
        <input type="hidden" name="hiddenId"  size="5%" id="hiddenId">
      </td>
    </tr>
    <tr>
     <td colspan="3">
       <input type="reset" name="reset" id="reset" value="Reset">
       <input type="submit" name="loanBtn" id="loanBtn" value="Save" />
       <input type="submit" name="loanPrintBtn" id="loanPrintBtn" onclick="savePrint();" value="Save & Print" />
     </td>
    </tr>
  </table>
</form> 
{/block}